package com.foreveross.crawl.application.computer;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.Properties;

/**
 * @author luofangyi
 *
 */
public abstract class AbstratComputerInfo {

	protected InetAddress address;
	
	
	
	public String getIpAddress() throws Exception {
		
		return address.getHostAddress();
	}
	
	/**
	 * 获取当前操作系统mac地址
	 * @throws SocketException
	 */
	public String getMACAddress() throws SocketException {
		// TODO Auto-generated method stub
		//获取网卡，获取地址
		byte[] mac = NetworkInterface.getByInetAddress(address).getHardwareAddress();
		StringBuffer sb = new StringBuffer("");
		for(int i=0; i<mac.length; i++) {
			if(i!=0) {
				sb.append("-");
			}
			//字节转换为整数
			int temp = mac[i]&0xff;
			String str = Integer.toHexString(temp);
			if(str.length()==1) {
				sb.append("0"+str);
			}else {
				sb.append(str);
			}
		}
		return sb.toString().toUpperCase();
	}
		
	/**
	 * 初始化不同操作系统下InetAddress
	 * @throws UnknownHostException
	 */
	public abstract void initInetAddress() throws Exception;
	
	/**  
	 * @Description: 获取不同操作系统CPU使用率
	 * @return
	 * @throws Exception
	 * @author luofangyi
	 * @date 2014-6-27 下午5:05:52 
	 */ 
	public abstract double getCpuRate();
}
